//
//  ViewController.m
//  Rac
//
//  Created by 崔博 on 2017/12/28.
//  Copyright © 2017年 崔博. All rights reserved.
//

#import "ViewController.h"
#import <ReactiveObjC/ReactiveObjC.h>
#import "BBview.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet BBview *bbview;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    //1.代替代理
    [[self.bbview rac_signalForSelector:@selector(add:)] subscribeNext:^(id  _Nullable x) {
        NSLog(@"%@",x);
    }];
    //2.代替kvo
    [[self.bbview rac_valuesForKeyPath:@"frame" observer:self] subscribeNext:^(id  _Nullable x) {
        NSLog(@"我改变了");
    }];
    //3.监听事件
    UIButton * btn;
    [[btn rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
        
    }];
    //4.代替通知
    [[[NSNotificationCenter defaultCenter] rac_addObserverForName:UIKeyboardWillShowNotification object:nil] subscribeNext:^(NSNotification * _Nullable x) {
        
    }];
    //5.监听文本框
    UITextView * text;
    [text.rac_textSignal subscribeNext:^(NSString * _Nullable x) {
        
    }];
    
    [self array];
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
    self.bbview.frame = CGRectMake(10, 10, 100, 100);
}
- (void)demo1{
    // 元祖
    RACTuple * tuple = [RACTuple tupleWithObjects:@[@"aa",@"bb",@(1)], nil];
    NSString * st= tuple[1];
}
- (void)array{
    NSArray * arra = @[@"aa",@"bb",@(1)];
    //    RACSequence * requence = arra.rac_sequence;
    //    // 遍历
    //    RACSignal * singa = requence.signal;
    //
    //    // 订阅信号
    //    [singa subscribeNext:^(id  _Nullable x) {
    //        NSLog(@"%@",x);
    //    }];
    [arra.rac_sequence.signal subscribeNext:^(id  _Nullable x) {
        
    }];
    
    // 字典
    NSDictionary * dic = @{@"name":@"111",@"age":@(18)};
    
    // 字典转集合
    [dic.rac_sequence.signal subscribeNext:^(RACTuple * _Nullable x) {
        
        RACTupleUnpack(NSString *key, NSString * value) = x;
        NSLog(@"%@---%@---%@",key,value,x);
    }];
}
@end
